* Importing parental pgs with genotypes imputed based on UKB 

* Identified by id_ukb, iid in this file
* UKB based 
clear all
cd "Analysis\"
import delimited "Input\parental_pgs\direct.pgs.ukb_based.txt", delimiter(space) 

rename iid id_ukb
rename proband ea_ukb_ld_proband
rename paternal ea_ukb_ld_paternal 
rename maternal ea_ukb_ld_maternal 

save "Input\parental_pgs\direct_pgs_ea_ukb_based.dta", replace 

* UKB 0 splitscores
clear all
cd "Analysis\"
import delimited "Input\parental_pgs\direct.pgs.ukb0.txt", delimiter(space) 

rename iid id_ukb
rename proband ea_ukb_ld_0_proband
rename paternal ea_ukb_ld_0_paternal 
rename maternal ea_ukb_ld_0_maternal 

save "Input\parental_pgs\direct_pgs_ea_ukb0_based.dta", replace

* UKB 1 splitscores
clear all
cd "Analysis\"
import delimited "Input\parental_pgs\direct.pgs.ukb1.txt", delimiter(space) 

rename iid id_ukb
rename proband ea_ukb_ld_1_proband
rename paternal ea_ukb_ld_1_paternal 
rename maternal ea_ukb_ld_1_maternal 

save "Input\parental_pgs\direct_pgs_ea_ukb1_based.dta", replace 
 

* merge all together 
merge 1:1 id_ukb using "Input\parental_pgs\direct_pgs_ea_ukb1_based.dta", gen(_ukb1)
merge 1:1 id_ukb using "Input\parental_pgs\direct_pgs_ea_ukb0_based.dta", gen(_ukb0)
merge 1:1 id_ukb using "Input\parental_pgs\direct_pgs_ea_ukb_based.dta", gen(_ukb)

* merge to norface key 
merge 1:1 id_ukb using "Input\ID_Norface_ID_UKB_key.dta", gen(_ids)

drop _23me _ukb1 _ukb0 _ukb 
drop _ids 
* save as one dataset 
save "Input\parental_pgs\parental_pgs.dta", replace 



* merge to birth order data 
*merge 1:1 ID using "Input\parental_pgs\parental_pgs.dta", gen(_ids)
